package com.zrrd.learn.chapter09.collection;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Stream;
/**
 * list的常用lambad表达式
 *
 * @author wrn
 * @version 1.0
 * @date 2023/8/14 10:53
 */


public class ListLambda {

    public static void main(String[] args) {
        List<String> list1 = Arrays.asList("张三","本四","张三丰","陈");

        for (int i = 0; i < list1.size(); i++) {

            System.out.printf("下标为%d,内容为%s\n",i,list1.get(i));

        }
        for (String s : list1) {
            System.out.printf("内容为%s\n",s);
        }

        //两种呢  iterator

        System.out.println("迭代器");

        Iterator<String> it = list1.iterator();
        for (; it.hasNext();) {
            String obj = it.next();
            System.out.println(obj);
        }

        for (Iterator<String> it1 = list1.iterator();it1.hasNext();) {
            String obj = it1.next();
            System.out.println(obj);
        }

        Iterator<String> it2 = list1.iterator();
        while (it2.hasNext()) {
            String str1 = it2.next();
            System.out.println(str1);
        }
        System.out.println("迭代器");

        System.out.println("lambad");

        list1.forEach((x)->{
            System.out.println(x);
        })  ;

        list1.forEach(x-> System.out.println(x));

        //函数调用

        list1.forEach(System.out::println);


//        Consumer: 消费型函数式接口

        // Stream 流.....

        System.out.println("来看一下stream流");

        list1.stream().filter(x->x.length()>=3).filter(x->x.startsWith("张")).forEach(System.out::println);
        System.out.println("来看一下stream流");
    }
}
